import apiClient from './axios'

// 走访计划相关的API接口
export interface VisitTarget {
  id?: string
  targetName: string
  targetType: string
  targetValue: string
  status?: string
}

export interface VisitPlan {
  id?: string
  planName: string
  customerId: string
  customerName: string
  startTime: string
  endTime: string
  manager: string
  contactPerson: string
  managerPhone: string
  status: string
  remark?: string
  targets: VisitTarget[]
  createTime?: string
  updateTime?: string
}

// 获取走访计划列表
export const getVisitPlanList = async (params?: {
  page?: number
  pageSize?: number
  status?: string
  keyword?: string
  dateRange?: string[]
}): Promise<{ data: VisitPlan[]; total: number }> => {
  return apiClient.get('/visit-plans', { params })
}

// 获取走访计划详情
export const getVisitPlanDetail = async (id: string): Promise<VisitPlan> => {
  return apiClient.get(`/visit-plans/${id}`)
}

// 创建走访计划
export const createVisitPlan = async (data: VisitPlan): Promise<VisitPlan> => {
  return apiClient.post('/visit-plans', data)
}

// 更新走访计划
export const updateVisitPlan = async (id: string, data: Partial<VisitPlan>): Promise<VisitPlan> => {
  return apiClient.put(`/visit-plans/${id}`, data)
}

// 批量创建走访计划
export const batchCreateVisitPlans = async (data: VisitPlan[]): Promise<VisitPlan[]> => {
  return apiClient.post('/visit-plans/batch', data)
}